package leetcode;

import java.util.ArrayList;
import java.util.List;

public class Test530 {
    class TreeNode {
        int val;

        TreeNode left;
        TreeNode right;

        TreeNode(int x){ val=x;}
    }

    public void run(){
        TreeNode root=new TreeNode(4);
        root.left=new TreeNode(1);
        root.right=new TreeNode(6);
        getMinimumDifference(root);
    }

    public int getMinimumDifference(TreeNode root){
        int min=0;
        List<Integer> list=new ArrayList<Integer>();
        diedai(root,list);
        for(int i=0;i<list.size();i++) {
            System.out.println(list.get(i));
        }
        for(int i=0;i<list.size()-1;i++){

            int cha=Math.abs(list.get(i)-list.get(i+1));
            if(min==0)
                min=cha;
            else {
                min=min>cha?cha:min;
            }
        }
        System.out.println(min);
        return min;
    }

    public void diedai(TreeNode parent, List<Integer> list){
        if(parent.left!=null){
            diedai(parent.left,list);
        }
        list.add(parent.val);
        if(parent.right!=null) {
            diedai(parent.right, list);
        }

    }
}
